#一列表List的CRUD
#1增加C
#1.1运算符增加
x = [1, 2, 3]
print("x = [1, 2, 3]的原始id为:{}".format(id(x)))
x += [4, 5]
print("x+=[4, 5]的结果为:{}".format(x))
print(" x+=[4, 5]后的x列表id为：{}".format(id(x)))
print("-----------------")
x = ["a"]
print("x列表的原始id为:{}".format(id(x)))
y = x*3
print("y= x*3的结果:{}".format(y))
print("y= x*3的id为:{}".format(id(y)))
print("-----------------")
x = "a"
print("'a'的原始id为:{}".format(id(x)))
y = ["a"]*3
print("y= ['a']*3的结果:{}".format(y))
print("y= ['a']*3的id为:{}".format(id(y)))
print("y[0]的id为:{}".format(id(y[0])))
print("-----------------")
x = "你"
print("'你'的原始id为:{}".format(id(x)))
y = ["你"]*3
print("y= ['你']*3的结果:{}".format(y))
print("y= ['你']*3的id为:{}".format(id(y)))
print("y[0]的id为:{}".format(id(y[0])))
print("-----------------")
#1.2append
x = [1, 2, 3]
x.append(4)
print(x)
print("-----------------")
#1.3insert
x = [1, 2, 3]
x.insert(1,4)
print(x)
print("-----------------")
#2检索(Retrieve)
x = [1, 2, 3, 4, 5]
print(x[1])
print(x[:])
print(x[1:])
print(x[:3])
print(x[2:3])
print(x[-1])
print(x[0:5:2])
#print(x.index("5"))
print(x.index(5))
print(x.insert(x.index(5), 6))
print("-----------------")
#3更新(Update)
x = [1, 2, 3, 4, 5]
x[0] = 2
print(x)
x[0:2] = ["a", "b", "c"]
print(x)
x[0:2] = "a", "b", "d"
print(x)
print("-----------------")
#4删除(Delete)
#4.1pop
x = [1, 2, 3, 4, 5]
print(x.pop())
print(x.pop())
print(x)
print("-----------------")
#4.2remove
print(x.remove(2))
print(x)
print("-----------------")
#4.3 count
x = [1, 2, 3, 2, 5, 2]
print(x.count(2))
print("-----------------")
#4.4reverse
x = [1, 5, 3, 2, 6]
print(x.reverse())
print(x)
print(list(reversed(x)))
print(x)
print("-----------------")
#4.5sort
x = [1, 5, 3, 2, 6]
x.sort()
print(x.sort())
print(x)
x = [1, 5, 3, 2, 6]
sorted(x)
print(sorted(x))
print(x)
print("-----------------")
#二 元组TUPLE
s = (1, 2, 3, 4)
print(s[1])
print(s[1:3])
print(s.index(3))
print("-----------------")
#三 字典Dict
#3.1 增加c
d = {}
d["a"] = 1
print(d)
print("-----------------")
d1 = {"a": 1, "b": 2}
d2 ={"c": 3}
print(d2.update(d1))
print(d2)
print("-----------------")
d1 = {"a": 1, "b": 2}
d1.setdefault("c",3)
print(d1)
d1.setdefault("c",8)
print(d1)
d1.setdefault("d",9)
print(d1)
print("-----------------")
#3.2检索(Retrieve)
d1 = {'a': 1, 'b': 2, 'c': 3}
print(d1["a"])
d1.get("b",9)
print(d1)
print("-----------------")
d1 = {'a': 1, 'b': 2, 'c': 3}
print(d1.keys())
print(d1.values())
print(d1.items())
print("-----------------")
d= {'a': 1, 'b': 2, 'c': 3}
d["a"]=5
print(d)
d= {'a': 1, 'b': 2, 'c': 3}
d1={'d': 1}
d.update(d1)
print(d)
d.pop("d")
print(d)
d.clear()
print(d)
print("-----------------")
#四 集合SET
#4.1增加
s={1, 2, 3}
s.add(4)
print(s)
#4.2检索
print(4 in s)
print(40 in s)
#4.3更新
s={1, 2, 3}
s1={4}
s.update(s1)
print(s)
print("-----------------")
s={1, 2, 3}
s1={4}
print(s.union(s1))
print(s)
print(s1)
print("-----------------")
#4.4删除
s = {1, 2, 3, 4}
s.remove(4)
print(s)
s.discard(2)
print(s)
s.discard(6)
print(s)
s.pop()
print(s)


#         C       R       U      D
#列表     YES      YES    YES     YES

#元组     NO       YES     NO     NO

#字典     YES      YES     YES    YES

#集合     YES       YES    YES    YES